package shuogg.test.servletbase;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.io.IOUtils;

@SuppressWarnings(value = { "all" })
public class OutImage extends HttpServlet {
    @Override
    public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        /* 输出工程里的图片比较原始的方法 */
        InputStream inputStream = OutImage.class.getResourceAsStream("/123.jpg");
        OutputStream outputStream = resp.getOutputStream();
        int ch;
        while ((ch = inputStream.read()) != -1) {
            outputStream.write(ch);
        }

        /* 使用IOUtils来输出系统里的图片 */
        FileInputStream in = new FileInputStream("F:/123.jpg");
        IOUtils.copy(in, outputStream);
        
        System.out.println("Image Output complete!");
    }

    @Override
    public void doPost(HttpServletRequest req, HttpServletResponse resp) {
        System.out.println("Do post!");
    }
}
